package Sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @author fly
 * @create 2021--03--16--11:08
 */
public class Acwing803 {

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        ArrayList<int[]> a=new ArrayList<>();
        ArrayList<int[]> b=new ArrayList<>();
        while(n-->0){
            int[] t=new int[2];
            t[0]=sc.nextInt();
            t[1]=sc.nextInt();
            a.add(t);
        }

        int N=-1000000000;
        int l=N,r=N;
        Collections.sort(a,new Comparator<int[]>(){
             public int compare(int[] o1,int[] o2){
                 return o1[0]-o2[0];
             }
        });

        for(int i=0;i<a.size();i++){
            int x=a.get(i)[0],y=a.get(i)[1];
            if(r<x){
                if(l!=N){
                    b.add(new int[]{l,r});
                }
                l=x;r=y;
            }else{
                r=Math.max(y,r);
            }
        }
        if(l!=N)b.add(new int[]{l,r});
        System.out.println(b.size());
    }
}
